<?php

class HTML_Option extends HTML implements HTMLElements  {
	
	private $attributeDisabled;
	private $attributeLabel;
	private $attributeSelected;
	private $attributeValue;
	
	const HTML_OPTION = 'option';
	
	
	const DISABLED_DISABLED = 'disabled=""';
	const DISABLED_ENABLED = '';
	const ATTRIBUTE_DISABLED = 'disabled';
	const ATTRIBUTE_LABEL = 'label';
	const SELECTED_SELECTED = ' selected=""';
	const SELECTED_UNSELECTED = '';
	const ATTRIBUTE_SELECTED = 'selected';
	const ATTRIBUTE_VALUE = 'value';
	
	/**
	 * 
	 * This function creates a complete Link-Element.
	 * The attributes have to be passed within an array. Possible attributes are:
	 * 	- $class
	 * 	- $id
	 * 	- $title
	 * @param unknown_type $parent
	 * @param String[][] $properties
	 */
	public function __construct($parent, $properties)  {
		PropertySetter::setProperties($this, $properties);
		$parent->addChildElement($this);
	}
	
	public function setAttributeDisabled ($disabled)  {
		$this->attributeDisabled = $disabled;
	}
	
	public function setAttributeLabel ($label)  {
		$this->attributeLabel = $label;
	}
	
	public function setAttributeSelected ($selected)  {
		$this->attributeSelected = $selected;
	}
	
	public function setAttributeName ($value)  {
		$this->attributeValue = $value;
	}
	
	public function getAttributeDisabled ()  {
		return $this->attributeDisabled;
	}
	
	public function getAttributeLabel ()  {
		return $this->attributeLabel;
	}
	
	public function getAttributeSelected ()  {
		return $this->attributeSelected;
	}
	
	public function getAttributeValue ()  {
		return $this->attributeValue;
	}
	
	public function getSelectAttributes ()  {
	
		$output = '';
	
		if (!empty($this->attributeDisabled))  {
			$output .= $this->getAttributeDisabled();
		}
		
		if (!empty($this->attributeLabel))  {
			$output .= ' '. self::ATTRIBUTE_LABEL. '="'. $this->getAttributeLabel(). '"';
		}
		
		if (!empty($this->attributeSelected))  {
			$output .= $this->getAttributeDisabled();
		}
		
		if (!empty($this->attributeValue))  {
			$output .= ' '. self::ATTRIBUTE_VALUE. '="'. $this->getAttributeValue(). '"';
		}
	
		if ($output == '')  {
			$output = ' ';
		}
	
		return $output;
	}
	
	public static function getAttributes ()  {
		$attributes = array();
		$parentAttributes = parent::getAttributes();
		$attributes[] = self::ATTRIBUTE_DISABLED;
		$attributes[] = self::ATTRIBUTE_LABEL;
		$attributes[] = self::ATTRIBUTE_SELECTED;
		$attributes[] = self::ATTRIBUTE_VALUE;
		return array_merge($parentAttributes, $attributes);
	}
	
	public function toString ()  {
		
		$output = '<'. self::HTML_OPTION.
					$this->getHTMLAttributes().
					$this->getSelectAttributes(). '>';
		
		if($this->getChildElements())  {
			foreach ($this->getChildElements() as $element)  {
				$output .= $element->toString();
			}
		}
		
		$output .= '</'. self::HTML_OPTION. '>';
		
		return $output;
	}
	
}